home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / xsw / buttons.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-09  |  8.0 KB  |  285 lines

  1. /***************************************************************************
  2.  *
  3.  *    Copyright (c) 1990-1993        The Santa Cruz Operation, Inc.
  4.  *
  5.  *    All rights reserved.  No part of this program or publication may be
  6.  *    reproduced, transmitted, transcribed, stored in a retrieval system,
  7.  *    or translated into any language or computer language, in any form or
  8.  *    by any means, electronic, mechanical, magnetic, optical, chemical,
  9.  *    biological, or otherwise, without the prior written permission of:
  10.  *
  11.  *        The Santa Cruz Operation , Inc.        (408) 425-7222
  12.  *        400 Encinal St., Santa Cruz, California 95060 USA
  13.  *
  14.  **************************************************************************/
  15.  
  16. /*
  17.  *    SCCS Stuff
  18.  *        
  19.  *    @(#) buttons.c 12.1 95/05/09 SCOINC
  20.  *
  21.  * S003, 15-Sep-93, rickra
  22.  *      ifdef out point_to_MyButton. This is no longer used since all 
  23.  *    buttons have now been replaced by motif buttons....
  24.  *
  25.  * S002, 51-May-93, rickra
  26.  *      Removed some dead code, PS button code. It has been replaced by
  27.  *    motif buttons now... Also, pass in current_server, rather that
  28.  *    using a global variable.
  29.  * S001, 01-Jan-93, rickra
  30.  *     Added support for seperate windows, support for buttons in
  31.  *    PSMEM.
  32.  * S000, 30-Sep-92, rickra
  33.  *     Added copyright and modification history
  34. */
  35.  
  36. /*+-------------------------------------------------------------------------
  37.     buttons.c - XSW button and status message handler
  38.     wht@n4hgf.Mt-Park.GA.US
  39.  
  40.   Defined functions:
  41.     disp_msg(pixel,msg)
  42.     draw_PS_MyButton(num,pixel,init_struct)
  43.     draw_MyButton(num,pixel,init_struct)
  44.     place_MyButtons_all_off()
  45.     point_to_MyButton(x,y)
  46.  
  47. --------------------------------------------------------------------------*/
  48. /*+:EDITS:*/
  49. /*:09-25-1990-05:11-wht@n4hgf-release heh-heh x0.22 preliminary */
  50. /*:09-20-1990-00:09-wht@n4hgf-scales, sysinfo/minfo, bootinfo working */
  51. /*:09-15-1990-14:47-wht-creation */
  52.  
  53. #include <X11/Xlib.h>
  54. #include <X11/Xutil.h>
  55. #include <X11/Intrinsic.h>
  56. #include <X11/Shell.h>
  57. #include <X11/StringDefs.h>
  58. #include <Xm/Xm.h>
  59. #include <Xm/MainW.h>
  60. #include <Xm/DrawingA.h>
  61.  
  62. #include "include/unixincs.h"
  63.  
  64. #include "include/buttons.h"
  65. #include "include/resources.h"
  66. #include "include/xsw.h"
  67.  
  68.  
  69. int             MyButton_TLX = 1;
  70. int             MyButton_TLY = 1;
  71.  
  72. int             MyButtons_next_tlx = 0;
  73. int             DispMsg_tlx = 70;
  74.  
  75. extern struct NetworkXswStruct *current_server;
  76.  
  77. extern MyResources res;
  78.  
  79.  
  80. /*+-------------------------------------------------------------------------
  81.     draw_PS_MyButton(num,ps_mode,pixel,pixel2,
  82.              init_struct,X_position,Y_position)
  83. --------------------------------------------------------------------------*/
  84. void
  85. draw_PS_MyButton (window, display, gc, DrawAreaXYWH,
  86.           num, ps_mode, pixel, pixel2,
  87.           init_struct, X_position, Y_position)
  88.      Window          window;
  89.      Display        *display;
  90.      GC              gc;
  91.      XWindowAttributes DrawAreaXYWH;
  92.      int             num;
  93.      int             ps_mode;
  94.      unsigned long   pixel;
  95.      unsigned long   pixel2;
  96.      int             init_struct;
  97.      int             X_position;
  98.      int             Y_position;
  99. {
  100.   MyButton       *butt;
  101.   int             line_style = LineSolid;
  102.   int             cap_style = CapButt;
  103.   int             join_style = JoinMiter;
  104.   int             x, y, w, h;
  105. #define BOXTHICKNESS 3        /* odd */
  106.  
  107.   if (ps_mode == BUTTON_ps_cpu)
  108.     butt = ¤t_server -> PS_MyButton_decl[num];
  109.   else if (ps_mode == BUTTON_ps_io)
  110.     butt = ¤t_server -> IO_PS_MyButton_decl[num];
  111.   else if (ps_mode == BUTTON_ps_mem)
  112.     butt = ¤t_server -> MEM_PS_MyButton_decl[num];
  113.  
  114.   if (init_struct)
  115.     {
  116.  
  117.       butt -> tlx = X_position;
  118.       butt -> tly = Y_position;
  119.       butt -> width = (strlen (butt -> label) * FWIDTH) + (2 * FGAP) +
  120.     BOXTHICKNESS;
  121.  
  122.       butt -> height = FASCENT;
  123.  
  124.       /* FHEIGHT + (2 * FGAP) + BOXTHICKNESS */ ;
  125.       butt -> brx = butt -> tlx + butt -> width;
  126.       butt -> bry = butt -> tly + butt -> height;
  127.     }
  128.  
  129.   /* draw the box */
  130.   XSetForeground (display, gc, /* foreground */ pixel);
  131.   XSetLineAttributes (display, gc, BOXTHICKNESS,
  132.               line_style, cap_style, join_style);
  133.   XDrawRectangle (display, window, gc,
  134.           x = butt -> tlx + (BOXTHICKNESS / 2),
  135.           y = butt -> tly,
  136.           w = butt -> width,
  137.           h = butt -> height);
  138.  
  139.   /* the "background" color */
  140.   XSetForeground (display, gc, pixel2);
  141.   XFillRectangle (display, window, gc, x, y, w, h);
  142.  
  143.   if (init_struct)
  144.     {
  145.       XPoint          rpoints[5];
  146.  
  147.       if (butt -> region)
  148.     XDestroyRegion (butt -> region);
  149.       rpoints[0].x = x;
  150.       rpoints[0].y = y;
  151.       rpoints[1].x = x + w;
  152.       rpoints[1].y = y;
  153.       rpoints[2].x = x + w;
  154.       rpoints[2].y = y + h;
  155.       rpoints[3].x = x;
  156.       rpoints[3].y = y + h;
  157.       rpoints[4].x = x;
  158.       rpoints[4].y = y;
  159.       butt -> region = XPolygonRegion (rpoints, 5, EvenOddRule);
  160.     }
  161.  
  162.   /* draw the label */
  163.   XSetForeground (display, gc, pixel);
  164.   XDrawString (display, window, gc,
  165.            butt -> tlx + BOXTHICKNESS + FGAP,
  166.      butt -> tly + BOXTHICKNESS + (FASCENT / 2) + FGAP /* + FASCENT */ ,
  167.            butt -> label, strlen (butt -> label));
  168.  
  169. }                /* end of draw_PS_MyButton */
  170.  
  171. #ifdef OLDWAY
  172. /*+-------------------------------------------------------------------------
  173.     point_to_MyButton(x,y)
  174.  
  175.     returns button number point is in, else -1
  176. --------------------------------------------------------------------------*/
  177. int
  178. point_to_MyButton (window, display, x, y)
  179.      Window          window;
  180.      Display        *display;
  181.      int             x;
  182.      int             y;
  183. {
  184.   int             ibutt;
  185.  
  186.   Window          root_window;
  187.   Window          child_return;
  188.   int             root_x_return, root_y_return;
  189.   int             win_x_return, win_y_return;
  190.   unsigned int    mask_return;
  191.  
  192.  
  193.   if (current_server -> COMMAND_LIST[BUTTON_ps_cpu].on == 1)
  194.     {
  195.       if (current_server -> SEPERATE_WINDOWS_LIST[BUTTON_ps_cpu].window == window)
  196.     {
  197.       for (ibutt = 0; ibutt < PS_MyButton_QUAN; ibutt++)
  198.         {
  199.           if (XPointInRegion (current_server -> PS_MyButton_decl[ibutt].region, x, y))
  200.         return (25 + ibutt);
  201.         }
  202.     }
  203.     }
  204.  
  205.   if (current_server -> COMMAND_LIST[BUTTON_ps_io].on == 1)
  206.     {
  207.       if (current_server -> SEPERATE_WINDOWS_LIST[BUTTON_ps_io].window == window)
  208.     {
  209.       for (ibutt = 0; ibutt < IO_PS_MyButton_QUAN; ibutt++)
  210.         {
  211.           if (XPointInRegion (current_server -> IO_PS_MyButton_decl[ibutt].region, x, y))
  212.         return (40 + ibutt);
  213.         }
  214.  
  215.     }
  216.  
  217.     }
  218.  
  219.   if (current_server -> COMMAND_LIST[BUTTON_ps_mem].on == 1)
  220.     {
  221.       if (current_server -> SEPERATE_WINDOWS_LIST[BUTTON_ps_mem].window == window)
  222.     {
  223.       for (ibutt = 0; ibutt < MEM_PS_MyButton_QUAN; ibutt++)
  224.         {
  225.           if (XPointInRegion (current_server -> MEM_PS_MyButton_decl[ibutt].region, x, y))
  226.         return (60 + ibutt);
  227.         }
  228.  
  229.     }
  230.  
  231.     }
  232.  
  233.  
  234.   return (-1);
  235. }                /* end of point_to_MyButton */
  236.  
  237. #endif
  238.  
  239. unsigned long   last_DispMsg_pixel = -1;
  240. char            last_DispMsg_msg[80] =
  241. {0x01, 0x00};
  242.  
  243. /*+-------------------------------------------------------------------------
  244.     disp_msg(pixel,msg)
  245.  
  246. This is put in here because the message area is on the second
  247. "line" of the window from the right of the buttons to the right hand
  248. side of the window
  249. --------------------------------------------------------------------------*/
  250. void
  251. disp_msg (pixel, msg)
  252.      unsigned long   pixel;
  253.      char           *msg;
  254. {
  255.   register int    y = Disp_msg_TLY;
  256.  
  257.   if (!window)
  258.     return;
  259. /*
  260.     if((pixel == last_DispMsg_pixel) && !strcmp(msg,last_DispMsg_msg))
  261.         return;
  262. */
  263.   XClearArea (display, window,
  264.           0, y, DrawAreaXYWH.width - (FWIDTH * 10), FHEIGHT, 0);
  265.   XSetForeground (display, gc, pixel);
  266.   XDrawString (display, window, gc,
  267.            0, y + FASCENT, msg, strlen (msg));
  268.   last_DispMsg_pixel = pixel;
  269.   strcpy (last_DispMsg_msg, msg);
  270. }                /* end of disp_msg */
  271.  
  272. /*+-------------------------------------------------------------------------
  273.     invalidate_last_DispMsg()
  274. --------------------------------------------------------------------------*/
  275. void
  276. invalidate_last_DispMsg ()
  277. {
  278.   last_DispMsg_pixel = -1;
  279.   last_DispMsg_msg[0] = 0x01;
  280.   last_DispMsg_msg[1] = 0x00;
  281. }                /* end of invalidate_last_DispMsg */
  282.  
  283. /* vi: set tabstop=4 shiftwidth=4: */
  284. /* end of buttons.c */
  285.